/**
 * @file DateType.c
 * @author 严一涵 (yyhhenry@foxmail.com)
 * @brief 日期处理类型
 * @version 0.1
 * @date 2022-05-14
 *
 * @copyright Copyright (c) 2022
 *
 */
#include "./DateType.h"

char *Date_getTime(int offset)
{
    time_t now = time(NULL);
    now += (time_t)(offset) * (24 * 60 * 60);
    struct tm *tmTime = localtime(&now);
    ListType *list = ListType_ListType(free);
    ListType_insert(list, NULL, Str_rJustFree(Str_fromInt(tmTime->tm_year + 1900), 4, '0'));
    ListType_insert(list, NULL, Str_rJustFree(Str_fromInt(tmTime->tm_mon + 1), 2, '0'));
    ListType_insert(list, NULL, Str_rJustFree(Str_fromInt(tmTime->tm_mday), 2, '0'));
    char *res = Str_join(list, "-");
    ListType_free(list);
    return res;
}
